<template>
	<page-meta :page-style="'overflow:'+(popShow?'hidden':'visible')"></page-meta>
	<view class="money-content">
		<headassy title="收支记录" searchTitle="工单单号" @goSearch="goSearch" @openSideBar="getAllSearch" @changeTab="changeTab" :tabs="tabs"></headassy>
		<view class="nav-status text-orange">
			当前状态有{{count}}个记录
		</view>
		<scroll-view>
			<view class="card-list">
				<view class="card mt-5" v-for="item in pageList" :key="item.id">
					<view class="top u-flex-between">
						<view class="left u-flex">
							<view class="text-info ">
								{{item.workNo}}
							</view>
						</view>
						<view class="right">
							<view class="cus-btn">
								{{item.receivePayStatus }}
							</view>
						</view>
					</view>
					<view class="center">
						<view class="title u-flex-between">
							<view class="title-left">
								收付款编号:
								<span style="margin-left: 14rpx;">{{item.number}}</span>
							</view>
						</view>
						<view class="text">
							客户/网点:
							<span style="margin-left: 14rpx;">{{item.partnerName}}</span>
						</view>
						<view class="text">
							收付金额:
							<span style="margin-left: 14rpx;">{{item.money}}</span>
						</view>
						<view class="text">
							收付类型:{{item.receivePayType }}
							<span style="margin-left: 14rpx;">{{item.receivePayType}}</span>
						</view>
						<view class="text">
							创建时间:
							<span style="margin-left: 14rpx;">{{item.createDate }}</span>
						</view>

					</view>
					<view class="down u-flex-content-end">
					<!-- 	<view class="right u-flex">
							<view class="cus-btn text-blue mr-5">
								配件费:{{item.spareFee}}
								<span style="color: red;">¥</span>
							</view>
							<view class="cus-btn text-blue mr-5">
								合计:{{item.workFee}}
								<span style="color: red;">¥</span>
							</view>
						</view> -->
					</view>
				</view>
			</view>
			<view class="example-body">
				<uni-load-more :status="status" :content-text="contentText"/>
			</view>
		</scroll-view>
		<!-- 侧边栏 -->
		<sidebarpop
			ref="page-sidebar"
			ptitle="筛选"
			isSlot="true"
			isDate="true"
			:height="(parseInt(system.safeArea.top) + 44)"
			@closeclick="closePop"
			@confirmDate="radioClick"
			@clearSelect="clearSelect"
			@saveclick="saveSelect"
		>
		</sidebarpop>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabIndex: 0,
				count: '',
				tabs: [
					{
						name: '待审核',
						disabled: false,
						param: {
							receivePayStatus: '1'
						}
					},
					{
						name: '已收款',
						disabled: false,
						param: {
							receivePayStatus: '2'
						}
					},
					{
						name: '已付款',
						disabled: false,
						param: {
							receivePayStatus: '3'
						}
					},
					{
						name: '全部状态',
						disabled: false,
						param: {
							receivePayStatus: ''
						}
					},
				],
				page: {
					pageNum: 1,
					pageSize: "10",
					searchType: "3",		// 搜索类型  1：客户、2：网点，3：工单单号
					custAccId: '',		
				},
				data: {
					startTime: "",			// 开始时间
					endTime: "",			// 结束时间
					search: "",				// 关键词搜索
					receivePayStatus: '',	// 状态 1：待审核。2：已收款。3：已付款，4：全部状态
				},
				pageList: [],				// 页面数据
				
				system: uni.getSystemInfoSync(),
				
				// 侧边栏
				popShow: false,				// 弹窗触发时为true
				popShowName: '',			// 弹窗名称
				
				
				// 加载动作
				status: 'loading',			//上拉加载
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
			};
		},
		onLoad() {
			this.page.custAccId = uni.getStorageSync('custAccid')
			this.getPullRefresh();
		},
		// 下拉刷新
		onPullDownRefresh() {
			this.getPullRefresh()
		},
		// 触底监听
		onReachBottom() {
			if(this.status != 'noMore') {
				return 
			}
			console.log('触底，列表分组总数:'+Math.ceil(this.count / 20),'当前列表:'+this.page.pageNum);
			if(this.page.pageNum < Math.ceil(this.count / 20)) {
				this.page.pageNum++;
				this.getPageList('refresh');
			}
		},
		methods: {
			// 下拉刷新请求数据
			getPullRefresh(){
				console.clear()
				setTimeout(()=>{
					uni.stopPullDownRefresh();
				}, 1500);
				this.page.pageNum = 1;
				this.getPageList();
			},
			
			async getPageList(type) {
				if(type != 'refresh') {
					this.pageList = [];
					this.count = 0;
					this.status = 'loading';
				}
				const res = await uni.$api.money.getFnanceLogList1(this.page.custAccId, {
					...this.page,
					...this.data,
				})
				if(type == 'refresh') {
					this.pageList.push(...res.data.rows);
				}else {
					this.pageList = res.data.rows
				}
				this.status = 'noMore';
				this.count = res.data.count
				uni.stopPullDownRefresh()
			},
			// 侧边栏模块标签点击
			radioClick(item,index,isRepeat) {
				console.log('侧边栏模块标签点击----',item,index,isRepeat)
				this.data.startTime = item.startTime;
				this.data.endTime = item.endTime;
			},
			// 确认筛选
			saveSelect() {
				this.page.pageNum = 1;
				this.getPageList();
				this.closePop();
			},
			// 清除数据
			clearSelect() {
				Object.keys(this.data).forEach(key => {
					this.data[key] = key != 'serviceId' ? '' : 1
				})
			},
			
			// 搜索
			goSearch(e) {
				this.data.singleNum = e;
				this.saveSelect();
			},
			
			// 切换tab
			changeTab(item) {
				console.log(item)
				this.tabIndex = item.index;
				this.data.receivePayStatus = item.param.receivePayStatus;
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 200
				});
				this.getPageList();
			},
			
			// 打开侧边栏
			getAllSearch() {
				this.openModel('page-sidebar');
			},
			// 新开弹窗
			openModel(ref) {
				if(this.$refs[ref]) {
					this.popShow = true;
					this.popShowName = ref;
					this.$refs[ref].pupshow = true;
				}
			},
			// 关闭弹窗
			closePop() {
				this.popShowName = '';
				this.popShow = false;
			},
		},

	}
</script>

<style lang="scss">
	// 去掉顶栏固定
	/deep/.u-navbar--fixed {
		position: static !important;
	}
	// 去掉默认背景色
	/deep/.u-popup__content {
		background-color: transparent !important;
	}
	
	.money-content {
		// height: 100vh;
		background-color: $uni-bg-color-grey;

		.tabs {
			background-color: #fff;
			font-size: 28rpx;
			width: 100%;
		}

		.nav-status {
			height: 100rpx;
			line-height: 100rpx;
			text-align: center;
			font-size: 28rpx;
		}

	.card-list {
				background: $uni-bg-color-grey;
	padding: 0 28rpx;
				.card {
					padding: 28rpx 32rpx;
					background: #fff;
	border-radius: 10rpx;
					margin-bottom: 28rpx;

				.top {
					border-bottom: solid 1px #f5f5f5;
					padding-bottom: 10px;

					.left {
						.text-info {
							font-size: 28rpx;
							font-weight: 700;
						}
					}
				}

			.center {
				padding-top: 10px;
				padding-bottom: 10px;
			
				.title {
					.title-left {
						font-size: 28rpx;
						color: gray;
					}
						.title-left {
							font-size: 28rpx;
						}

						.title-right {
							font-size: 28rpx;
						}
					}

					.text {
						font-size: 28rpx;
						color: gray;
					}
				}

				.down {
					border-top: solid 1px #f5f5f5;
					padding-top: 12px;
				}
			}
		}
	}
</style>